package com.rabbit.eap.controller.system;

import com.rabbit.eap.framework.common.api.ApiResult;
import com.rabbit.eap.framework.common.controller.BaseController;
import com.rabbit.eap.framework.core.validator.groups.AddGroup;
import com.rabbit.eap.framework.core.validator.groups.UpdateGroup;
import com.rabbit.eap.framework.log.annotation.Module;
import com.rabbit.eap.framework.log.annotation.OperationLog;
import com.rabbit.eap.framework.log.enums.OperationLogType;
import com.rabbit.eap.system.dto.SysPostDTO;
import com.rabbit.eap.system.param.SysPostPageParam;
import com.rabbit.eap.system.service.ISysPostService;
import com.rabbit.eap.system.vo.SysPostVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: eap
 * @packageName: com.rabbit.eap.system.controller
 * @className: SysPostController
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/06/06 23:05:26
 * <p>Description:
 * 岗位信息表 控制器
 * </p>

 */
@Slf4j
@RestController
@RequestMapping("/system/sysPost")
@Module("system")
@Api(value = "岗位信息表API", tags = {"岗位信息表"})
public class SysPostController extends BaseController {

    @Autowired
    private ISysPostService sysPostService;


    /**
    * @Description: 添加岗位信息表
    * @methodName: saveSysPost
    * @param sysPostDTO:sysPostDTO数据传输对象
    * @return: ApiResult.result(flag)
    * @date: 2020/06/06 23:05:26
    * @author: rabbit
    */
    @PostMapping("/saveSysPost")
    @RequiresPermissions("sys:post:add")
    @OperationLog(name = "添加岗位信息表", type = OperationLogType.ADD)
    @ApiOperation(value = "添加岗位信息表", response = ApiResult.class)
    public ApiResult saveSysPost(@Validated(AddGroup.class) @RequestBody SysPostDTO sysPostDTO) throws Exception {
        ApiResult apiResult = sysPostService.saveSysPost(sysPostDTO);
        return apiResult;
    }
    /**
     * @Description: 修改岗位信息表
     * @methodName: modifySysPost
     * @param  sysPostDTO:sysPostDTO数据传输对象
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @PutMapping("/modifySysPost")
    @RequiresPermissions("sys:post:edit")
    @OperationLog(name = "修改岗位信息表", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改岗位信息表", response = ApiResult.class)
    public ApiResult modifySysPost(@Validated(UpdateGroup.class) @RequestBody SysPostDTO sysPostDTO) throws Exception {
        ApiResult  apiResult = sysPostService.modifySysPost(sysPostDTO);
        return apiResult;
    }
    /**
     * @Description: 删除岗位信息表
     * @methodName: removeSysPost
     * @param ids:id集合
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @DeleteMapping("/removeSysPost")
    @RequiresPermissions("sys:post:remove")
    @OperationLog(name = "删除岗位信息表", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除岗位信息表", response = ApiResult.class)
    public ApiResult  removeSysPost(@RequestParam("ids") Long[] ids) throws Exception {
        ApiResult  apiResult = sysPostService.removeSysPost(ids);
        return apiResult;
    }

    /**
     * @Description: 根据Id获取岗位信息表详情
     * @methodName: getSysPostInfo
     * @param id: id
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysPostInfo")
    @RequiresPermissions("sys:post:query")
    @OperationLog(name = "岗位信息表详情", type = OperationLogType.INFO)
    @ApiOperation(value = "岗位信息表详情", response = SysPostVO.class)
    public ApiResult getSysPostInfo(@RequestParam("id") Long id) throws Exception {
        ApiResult apiResult = sysPostService.getSysPostById(id);
        return apiResult;
    }

    /**
     * @Description: 岗位信息表分页列表
     * @methodName: getSysPostPageList
     * @param sysPostPageParam
     * @return: ApiResult
     * @date: 2020/06/06 23:05:26
     * @author: rabbit
     */
    @GetMapping("/getSysPostPageList")
    @RequiresPermissions("sys:post:list")
    @OperationLog(name = "岗位信息表分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "岗位信息表分页列表", response = SysPostVO.class)
    public ApiResult getSysPostPageList(@Validated SysPostPageParam sysPostPageParam) throws Exception {
        ApiResult  apiResult = sysPostService.getSysPostPageList(sysPostPageParam);
        return apiResult;
    }

    /**
     * @Description: 修改岗位状态
     * @methodName: changeStatus
     * @param sysPostDTO:
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/10/4 10:55
     * @author: rabbit
     *
     */
    @PutMapping("/changeStatus")
    @RequiresPermissions("sys:post:edit")
    @OperationLog(name = "修改岗位状态", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改岗位状态", response = SysPostVO.class)
    public ApiResult changeStatus(@Validated SysPostDTO sysPostDTO){
        ApiResult apiResult = sysPostService.changeStatus(sysPostDTO);
        return apiResult;
    }
    /**
     * @Description: 获取所有可用的部门
     * @methodName: getAllPost
     * @param :
     * @return: com.rabbit.eap.framework.common.api.ApiResult
     * @date: 2020/10/28 09:26
     * @author: rabbit
     *
     */
    @GetMapping("/getAllPost")
    @OperationLog(name = "获取所有可用的部门", type = OperationLogType.LIST)
    @ApiOperation(value = "获取所有可用的部门", response = SysPostVO.class)
    public ApiResult getAllPost(){
        ApiResult apiResult = sysPostService.getAllPost();
        return apiResult;
    }
}

